package cn.tedu.ivoscm.application.controller;

import cn.tedu.ivoscm.application.pojo.dto.ApplicationQuery;
import cn.tedu.ivoscm.application.pojo.dto.ApplicationSaveParam;
import cn.tedu.ivoscm.application.pojo.vo.ApplicationVO;
import cn.tedu.ivoscm.application.service.ApplicationService;
import cn.tedu.ivoscm.base.response.JsonResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/application")
@Api(tags = "06.申请管理")
public class ApplicationController {
    @Autowired
    private ApplicationService applicationService;

    @PostMapping("save")
    public JsonResult save(ApplicationSaveParam asp) {
        log.debug("开始处理申请用车请求：{}", asp);
        applicationService.save(asp);
        return JsonResult.ok();
    }

    @GetMapping("select")
    public JsonResult select(ApplicationQuery aq) {
        log.debug("开始处理查询申请请求：{}", aq);
        List<ApplicationVO> list = applicationService.select(aq);
        return JsonResult.ok(list);
    }

    @PostMapping("cancel/{id}")
    public JsonResult cancel(@PathVariable  Long id) {
        log.debug("开始处理取消申请请求：{}", id);
        applicationService.cancel(id);
        return JsonResult.ok();
    }
}
